﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TPTecnicas.MessageProcessor.Common;
using TPTecnicas.MessageProcessor.Persistence;


namespace TPTecnicas.MessageProcessor.Persistence
{
	public class AccountRepository : IRepository<AccountDC>
	{
		SQLDataBaseContext Context;

		public AccountRepository(SQLDataBaseContext context)
		{
			Context = context;
		}

		
		public void Add(AccountDC entity)
		{
			Context.DataContext.AccountDCs.InsertOnSubmit(entity);
			Commit();
		}

		public IEnumerable<AccountDC> Where(System.Linq.Expressions.Expression<Func<AccountDC, bool>> predicate)
		{
			throw new NotImplementedException();
		}

		public IEnumerable<AccountDC> Get(System.Linq.Expressions.Expression<Func<AccountDC, bool>> predicate)
		{
			throw new NotImplementedException();
		}


		public AccountDC Get(long id)
		{
			var accountDC = (from t in Context.DataContext.AccountDCs where t.id == id
							select t).Single<AccountDC>();
			return accountDC;
		}

		public IEnumerable<AccountDC> GetAll()
		{
			return Context.DataContext.AccountDCs.ToList<AccountDC>();
		}

		public AccountDC First(System.Linq.Expressions.Expression<Func<AccountDC, bool>> predicate)
		{
			throw new NotImplementedException();
		}

		public AccountDC Find(params object[] keyValues)
		{
			throw new NotImplementedException();
		}

		public bool ExistMail(string mail)
		{
			int encontrado = 0;
			encontrado = (from t in Context.DataContext.AccountDCs
							 where t.mail == mail
							 select t).ToList<AccountDC>().Count;
			return ((encontrado > 0) ? true : false);
		}

		public void Update(AccountDC entity)
		{
			throw new NotImplementedException();
		}

		public void Delete(AccountDC entity)
		{
			throw new NotImplementedException();
		}

		public void Detach(AccountDC entity)
		{
			throw new NotImplementedException();
		}

		public void Commit()
		{
			try
			{
				Context.DataContext.SubmitChanges();
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
